/*
 * File:   TesseractExecutorTest.cpp
 * Author: Guilherme Monteiro
 *
 */

#include "TesseractExecutorTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION(TesseractExecutorTest);

TesseractExecutorTest::TesseractExecutorTest() {
}

TesseractExecutorTest::~TesseractExecutorTest() {
}

void TesseractExecutorTest::setUp() {
}

void TesseractExecutorTest::tearDown() {
}

void TesseractExecutorTest::testExecute() {
//    vector<Cell> cells;
//    cells.push_back(Cell(cvPoint(39,38), cvPoint(440,112)));
//    cells.push_back(Cell(cvPoint(440,112), cvPoint(915,158)));
//    cells.push_back(Cell(cvPoint(915,112), cvPoint(1304,158)));
//    cells.push_back(Cell(cvPoint(1304,112), cvPoint(1693,158)));
//    cells.push_back(Cell(cvPoint(1693,112), cvPoint(2157,158)));
    
    string highTablePath = "/books/caracterizacao/metadados/tabelasAlta/image278_0.png";
    TessMetaInfo* meta = new TessMetaInfo(highTablePath);
    ImageFormatConverter* converter = new ImageFormatConverter(meta);
    converter->convertToTiffFormat();
            
    Reader* reader = new Reader(meta->getUserAnswerPath());
    vector<Cell> cells = reader->readCells();
    
    TesseractExecutor* tesseractExecutor;
    try {
        tesseractExecutor = new TesseractExecutor(cells, meta->getHighResolutionTablePath());
    }
    catch(NullImageException nie) {
        cerr << nie.what() << endl;
    }
    
    vector<Transcription*> results = tesseractExecutor->runTesseract();
    
    if (results.size() != 66) {
        CPPUNIT_ASSERT(false);
    }
    
    if(strcmp(results[7]->getText().c_str(), "Estado") != 0) {
        CPPUNIT_ASSERT(false);
    }
    
    if(strcmp(results[14]->getText().c_str(), "1970") != 0) {
        CPPUNIT_ASSERT(false);
    }
    
    if(strcmp(results[15]->getText().c_str(), "1980") != 0) {
        CPPUNIT_ASSERT(false);
    }
    
    if(strcmp(results[16]->getText().c_str(), "1991") != 0) {
        CPPUNIT_ASSERT(false);
    }
    
    if(strcmp(results[17]->getText().c_str(), "1996") != 0) {
        CPPUNIT_ASSERT(false);
    }
    
    vector<Transcription*>::iterator itTrans;
    for(itTrans = results.begin(); itTrans != results.end(); itTrans++) {
        if((*itTrans)->getMeanTextConfidence() < 0 || (*itTrans)->getMeanTextConfidence() > 100) {
            CPPUNIT_ASSERT(false);
        }
    }
}

